/**
 * Created by YESO on 2015/12/16.
 */
function WxCtrl($scope, getsignservice) {
    $scope.url = "http://yzd.shuwang.info/wxpay-jsapi/airkiss1.0/index.html";

    //获取签名
    $scope.getsign = function () {
        getsignservice.sign($scope.url, function (data) {
            $scope.signdata = data;
            $scope.sign = $scope.signdata.sign;
            //alert("$scope.sign:"+$scope.sign);
            $scope.timestamp = $scope.signdata.timestamp;
            $scope.noncestr = $scope.signdata.noncestr;
            $scope.appId = $scope.signdata.appId;
            $scope.wifi();
            //$scope.config();
        });
    }
    $scope.wifi = function(){
        wx.config({
            beta: true, // 开启内测接口调用，注入wx.invoke方法
            debug: false, // 开启调试模式
            appId: $scope.appId, // 第三方app唯一标识
            timestamp: $scope.timestamp, // 生成签名的时间戳
            nonceStr: $scope.noncestr, // 生成签名的随机串
            signature: $scope.sign,// 签名
            jsApiList: ['configWXDeviceWiFi'] // 需要使用的jsapi列表
        });
        wx.ready(function () {
            wx.checkJsApi({
                jsApiList: ['configWXDeviceWiFi'],
                success: function (res) {
                    wx.invoke('configWXDeviceWiFi', {}, function (res) {
                        var err_msg = res.err_msg;
                        if (err_msg == 'configWXDeviceWiFi:ok') {
                            alert("配置成功");
                        } else if (err_msg=='configWXDeviceWiFi:cancel'){
                            alert("取消配置");
                        } else {
                            alert("配置失败");
                        }
                    });
                }
            });
        });
    }


}
